//package com.plian.system.service.pm.listedcompany.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.plian.Tools.*;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.cache.UserCache;
//import com.plian.system.common.status.CheckStatus;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.constant.yth.YthConstant;
//import com.plian.system.dto.pm.listedcompany.EarningsReportDTO;
//import com.plian.system.entity.pm.listedcompany.BaseEarningsExecute;
//import com.plian.system.entity.pm.listedcompany.BaseEarningsSummary;
//import com.plian.system.entity.pm.listedcompany.EarningsDetail;
//import com.plian.system.entity.pm.listedcompany.EarningsExecuteDetail;
//import com.plian.system.entity.sys.ApprovalMessage;
//import com.plian.system.mapper.pm.listedcompany.BaseEarningsExecuteMapper;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.mybatis.base.BaseFlowService;
//import com.plian.system.mybatis.base.BaseServiceImpl;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.properties.GzwProperties;
//import com.plian.system.service.pm.listedcompany.IBaseEarningsExecuteService;
//import com.plian.system.service.pm.listedcompany.IBaseEarningsSummaryService;
//import com.plian.system.service.pm.listedcompany.IEarningsDetailService;
//import com.plian.system.service.pm.listedcompany.IEarningsExecuteDetailService;
//import com.plian.system.service.sys.code.IFormCodeService;
//import com.plian.system.service.sys.message.IApprovalMessageService;
//import com.plian.system.service.sys.orgzation.IOrgService;
//import com.plian.system.service.sys.user.ISysUserService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.pm.listedcompany.BaseEarningsExecuteVO;
//import com.plian.system.vo.pm.listedcompany.EarningsReportVO;
//import com.plian.system.vo.report.HeaderVO;
//import com.plian.system.vo.report.ReportReturnVO;
//import com.plian.system.vo.report.ReportVO;
//import com.plian.system.vo.yth.YthResult;
//import com.plian.system.wrapper.pm.listedcompany.BaseEarningsExecuteWrapper;
//import lombok.AllArgsConstructor;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.web.bind.annotation.RequestBody;
//
//import java.util.*;
//import java.util.stream.Collectors;
//
//import static com.plian.system.constant.sys.ApprovalMessageTypeConstant.INVESTMENT_EXECUTION;
//import static com.plian.system.constant.sys.ApprovalMessageTypeConstant.KT_TYPE;
//import static com.plian.system.constant.sys.FormStatusConstant.UNREVIEWED;
//import static com.plian.system.constant.sys.FormTypeConstant.QM_EARNING_EXECUTION_REPORT;
//import static com.plian.system.constant.sys.FormTypeConstant.QM_EARNING_EXECUTION_REPORT_GZW;
//
///**
// * @Description: TODO
// * @Author: Take-off
// * @Date: 2023/2/28 8:00 PM
// * @Param
// * @return
// * @Version: 1.0
// **/
//@Service
//@AllArgsConstructor
//public class BaseEarningsExecuteServiceImpl extends BaseServiceImpl<BaseEarningsExecuteMapper, BaseEarningsExecute> implements IBaseEarningsExecuteService, BaseFlowService {
//
//    private final IEarningsExecuteDetailService earningsExecuteDetailService;
//
//    private final BaseEarningsExecuteWrapper earningsExecuteWrapper;
//
//    private final FormWorkflowService formWorkflowService;
//
//    private final IFormCodeService formCodeService;
//
//    private final GzwProperties gzwProperties;
//
//    private final IBaseEarningsSummaryService earningsSummaryService;
//
//    private final IEarningsDetailService earningsDetailService;
//
//    private IOrgService orgService;
//
//    private ISysUserService userService;
//
//    private IApprovalMessageService approvalMessageService;
//    @Override
//    public boolean saveOrUpdate(BaseEarningsExecute baseEarningsExecute) {
//        boolean flag = false;
//        if (!Optional.ofNullable(baseEarningsExecute.getStatus()).isPresent()) {
//            baseEarningsExecute.setStatus(FormStatusConstant.UNREVIEWED);
//        }
//        if (baseEarningsExecute.getStatus().equals(FormStatusConstant.REJECT)) {
//            baseEarningsExecute.setStatus(FormStatusConstant.UNREVIEWED);
//        }
//        if (!Optional.ofNullable(baseEarningsExecute.getId()).isPresent()) {
//            baseEarningsExecute.setCode(formCodeService.getCode(Integer.parseInt(baseEarningsExecute.getFormType())));
//        }
//        boolean result = super.saveOrUpdate(baseEarningsExecute);
//        return result;
//    }
//
//    @Override
//    public boolean deleteLogic(List<Long> ids) {
//        for (Long id : ids) {
//            BaseEarningsExecute baseEarningsExecute = getById(id);
//            if (baseEarningsExecute == null) {
//                return false;
//            } else if (baseEarningsExecute.getStatus() != null &&
//                    (baseEarningsExecute.getStatus() != FormStatusConstant.STASH && baseEarningsExecute.getStatus() != FormStatusConstant.UNREVIEWED)) {
//                return false;
//            }
//            formWorkflowService.deleteProcessInstance(String.valueOf(id));
//        }
//        boolean result = super.deleteLogic(ids);
//        if (result){
//            earningsExecuteDetailService.deleteByParentId(ids);
//        }
//        return result;
//    }
//
//    @Override
//    @Transactional(rollbackFor=RuntimeException.class)
//    public boolean submit(BaseEarningsExecute baseEarningsExecute) {
//        boolean result = saveOrUpdate(baseEarningsExecute);
//        if (result){
//            List<EarningsExecuteDetail> earningsExecuteDetails = baseEarningsExecute.getEarningsExecuteDetails();
//            if (CollectionUtil.isNotEmpty(earningsExecuteDetails)){
//                for (EarningsExecuteDetail executeDetail : earningsExecuteDetails){
//                    if (executeDetail.getId() != null &&
//                            Optional.ofNullable(executeDetail.getIsDeleted()).isPresent() && executeDetail.getIsDeleted().intValue() == 1) {
//                        earningsExecuteDetailService.removeById(executeDetail.getId());
//                    }else {
//                        executeDetail.setBaseId(baseEarningsExecute.getId());
//                        earningsExecuteDetailService.saveOrUpdate(executeDetail);
//                    }
//                }
//            }
//        }
//        return result;
//    }
//
//    @Override
//    public BaseEarningsExecuteVO getDetailObj(BaseEarningsExecute baseEarningsExecute) {
//        BaseEarningsExecute detail = getOne(Condition.getQueryWrapper(baseEarningsExecute));
//        BaseEarningsExecuteVO baseEarningsExecuteVO = earningsExecuteWrapper.entityToVO(detail);
//        //子项
//        List<EarningsExecuteDetail> details = earningsExecuteDetailService.list(new LambdaQueryWrapper<EarningsExecuteDetail>().eq(EarningsExecuteDetail::getBaseId, baseEarningsExecute.getId()));
//        baseEarningsExecuteVO.setEarningsExecuteDetails(details);
//        return baseEarningsExecuteVO;
//    }
//
//    @Override
//    public ListResult<BaseEarningsExecuteVO> list(@RequestBody Query query) {
//        List<SearchEntity> entityList = query.getSearch();
//        if (query.getAscs()==null&&query.getDescs()==null){
//            query.setDescs("create_time");
//        }
//        QueryWrapper<BaseEarningsExecute> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new BaseEarningsExecute()), entityList
//        );
//        //只查看自己填写的单据
//        String orgId = TokenUtil.getTokenOrgId();
//        if ( !gzwProperties.getIsGzw(orgId)){
//            queryWrapper.eq("filling_org_id", orgId);
//        }
//
//        IPage<BaseEarningsExecute> pages = page(Condition.getPage(query), queryWrapper);
//        List<BaseEarningsExecuteVO> baseEarningsExecuteVOS = earningsExecuteWrapper.entityToVO(pages.getRecords());
//        ListResult<BaseEarningsExecuteVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//        listResult.setList(baseEarningsExecuteVOS);
//        listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//        return listResult;
//    }
//
//
//    @Override
//    public HashMap<String,Object> commit(String id) {
//        handleStatus(Long.valueOf(id), FormStatusConstant.FLOW, null);
//
//        //将需要提交的流程变量返回，用于工作流侧
//        return new HashMap<String,Object>();
//    }
//
//    @Override
//    public Boolean finish(String id) {
//        return handleStatus(Long.valueOf(id), FormStatusConstant.FINISH, "审批通过");
//    }
//
//    @Override
//    public Boolean reject(String id, int formState,String comment) {
//        return handleStatus(Long.valueOf(id), formState, comment);
//    }
//
//    @Override
//    public List<PageData> findByIds(List<String> formIds) {
//        LambdaQueryWrapper<BaseEarningsExecute> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.in(BaseEarningsExecute::getId, Func.toLongList(StringUtils.join(formIds, StringPool.COMMA)));
//        List<BaseEarningsExecute> baseEarningsExecutes = list(queryWrapper);
//        List<BaseEarningsExecuteVO> baseEarningsExecuteVOS = earningsExecuteWrapper.entityToVO(baseEarningsExecutes);
//        List<PageData> pageDataList = new ArrayList<>();
//        try{
//            if (CollectionUtil.isNotEmpty(baseEarningsExecuteVOS)){
//                for (BaseEarningsExecuteVO vo : baseEarningsExecuteVOS){
//                    PageData pd = new PageData();
//                    pd.put("id", vo.getId());
//                    pd.put("UNITNAME", vo.getFillingOrgName());
//                    pd.put("APPLICANTNAME", vo.getCreateUserName());
//                    pd.put("applicantId", vo.getCreateUser());
//                    pd.put("applyOrganizationId", vo.getCreateCompanyId());
//                    pd.put("formType", vo.getFormType());
//                    pd.put("orgName", vo.getFillingOrgName());
//                    pageDataList.add(pd);
//                }
//            }
//
//            return pageDataList;
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//        }
//        return pageDataList;
//    }
//
//    /**
//     * QM_EARNING_EXECUTION_REPORT_GZW
//     * @return
//     */
//    @Override
//    public List<Integer> getFormType() {
//        return Arrays.asList(QM_EARNING_EXECUTION_REPORT, QM_EARNING_EXECUTION_REPORT_GZW);
//    }
//
//    @Override
//    public void goBackToStash(String formId) {
//        handleStatus(Long.valueOf(formId), UNREVIEWED, null);
//    }
//
//    @Override
//    public ReportReturnVO report(EarningsReportDTO dto){
//        ReportReturnVO reportReturnVO = new ReportReturnVO();
//
//        List<String> orgIds = dto.getOrgIds();
//        String orgName = dto.getOrgName();
//        String year = dto.getYear();
//        List<EarningsReportVO> earningsReportVOS = new ArrayList<>();
//        //上一年
//        String lastYear = DateUtil.format(DateUtil.minusYears(DateUtil.parse(year, DateUtil.PATTERN_YEAR), 1), DateUtil.PATTERN_YEAR);
//        //预算主表
//        List<BaseEarningsSummary> thisYearSummary = earningsSummaryService.list(new LambdaQueryWrapper<BaseEarningsSummary>().eq(BaseEarningsSummary::getStatus, 3).in(BaseEarningsSummary::getFillingOrgId, orgIds)
//                .eq(BaseEarningsSummary::getReportYear, year));
//        List<BaseEarningsSummary> lastYearSummary = earningsSummaryService.list(new LambdaQueryWrapper<BaseEarningsSummary>().eq(BaseEarningsSummary::getStatus, 3).in(BaseEarningsSummary::getFillingOrgId, orgIds)
//                .eq(BaseEarningsSummary::getReportYear, lastYear));
//
//        //预算详情
//        List<EarningsDetail> thisYearSummaryDetails = getSummaryDetail(thisYearSummary,orgName);
//        List<EarningsDetail> lastYearSummaryDetails = getSummaryDetail(lastYearSummary,orgName);
//
//        //执行主表
//        List<BaseEarningsExecute> thisYearExecute = list(new LambdaQueryWrapper<BaseEarningsExecute>().eq(BaseEarningsExecute::getStatus, 3).in(BaseEarningsExecute::getFillingOrgId, orgIds)
//                .eq(BaseEarningsExecute::getReportYear, year));
//        List<BaseEarningsExecute> lastYearExecute = list(new LambdaQueryWrapper<BaseEarningsExecute>().eq(BaseEarningsExecute::getStatus, 3).in(BaseEarningsExecute::getFillingOrgId, orgIds)
//                .eq(BaseEarningsExecute::getReportYear, lastYear));
//
//        //执行详情
//        List<EarningsExecuteDetail> thisYearExecuteDetails = getExecuteDetail(thisYearExecute,orgName);
//        List<EarningsExecuteDetail> lastYearExecuteExecuteDetails = getExecuteDetail(lastYearExecute,orgName);
//        int index = 1;
//        if (CollectionUtil.isNotEmpty(thisYearSummaryDetails)){
//            //以今年投资企业为  主体
//            for (EarningsDetail earningsDetail:thisYearSummaryDetails){
//                //组织名称去匹配
//                String fillingOrgName = earningsDetail.getFillingOrgName();
//                //今年预算
//                EarningsReportVO earningsReportVO = new EarningsReportVO();
//                earningsReportVO.setIndexNum(index + "");
//                index++;
//                earningsReportVO.setFillingOrgName(earningsDetail.getFillingOrgName());
//                earningsReportVO.setThisBudget(earningsDetail.getBudget());
//                earningsReportVO.setProvinceShare(earningsDetail.getProvinceShare());
//                earningsReportVO.setSocialSecurityBudget(earningsDetail.getSocialSecurityBudget());
//
//                setReportVO(earningsDetail, earningsReportVO);
//                //去年预算
//                lastYearSummaryDetails.stream().filter(m -> Optional.ofNullable(m.getFillingOrgName()).isPresent() && m.getFillingOrgName().equals(fillingOrgName)).findFirst().ifPresent(m -> {
//                    earningsReportVO.setLastProvinceShare(m.getProvinceShare());
//                    earningsReportVO.setLastSecurityBudget(m.getSocialSecurityBudget());
//                });
//                earningsReportVOS.add(earningsReportVO);
//
//                //去年执行
//                lastYearExecuteExecuteDetails.stream().filter(m -> Optional.ofNullable(m.getFillingOrgName()).isPresent() && m.getFillingOrgName().equals(fillingOrgName)).findFirst().ifPresent(m -> {
//                    earningsReportVO.setLastExecute(m.getExecute());
//                });
//                //今年执行
//                thisYearExecuteDetails.stream().filter(m -> Optional.ofNullable(m.getFillingOrgName()).isPresent() && m.getFillingOrgName().equals(fillingOrgName)).findFirst().ifPresent(m -> {
//                    earningsReportVO.setThisExecute(m.getExecute());
//                    earningsReportVO.setThisSecurityExecute(m.getSocialSecurityExecute());
//                    earningsReportVO.setRemark(m.getRemark());
//                });
//            }
//            //合计
//            getTotalReportVO(earningsReportVOS);
//
//            //其他
//            getOtherReportVO(earningsReportVOS, lastYearExecute, thisYearExecute);
//        }else if (CollectionUtil.isNotEmpty(lastYearSummaryDetails)){
//            //去年年投资企业为主体
//            for (EarningsDetail lastDetail:lastYearSummaryDetails){
//                String fillingOrgName = lastDetail.getFillingOrgName();
//                EarningsReportVO earningsReportVO = new EarningsReportVO();
//                earningsReportVO.setIndexNum(index + "");
//                index++;
//                setReportVO(lastDetail, earningsReportVO);
//                earningsReportVO.setLastProvinceShare(lastDetail.getProvinceShare());
//                earningsReportVO.setLastSecurityBudget(lastDetail.getSocialSecurityBudget());
//
//                //去年执行
//                lastYearExecuteExecuteDetails.stream().filter(m -> Optional.ofNullable(m.getFillingOrgName()).isPresent() && m.getFillingOrgName().equals(fillingOrgName)).findFirst().ifPresent(m -> {
//                    earningsReportVO.setLastExecute(m.getExecute());
//                });
//            }
//        }
//        ReportVO reportVO = new ReportVO();
//
//        reportVO
//                .addHeader(HeaderVO.builder().key("indexNum").title("序号").build())
//                .addHeader(HeaderVO.builder().key("fillingOrgName").title("企业名称").build())
//                .addHeader(HeaderVO.builder().key("enterpriseType").title("企业类别").build())
//                .addHeader(HeaderVO.builder().key("lastExecute").title(lastYear+"年收益执行数").build())
//                .addHeader(HeaderVO.builder().key("lastProvinceShare").title(lastYear+"年省财开持股比例（%)").build())
//                .addHeader(HeaderVO.builder().key("lastSecurityBudget").title(lastYear+"年实际划转社保收益").build())
//                .addHeader(HeaderVO.builder().key("thisBudget").title(year+"年收益预算数").build())
//                .addHeader(HeaderVO.builder().key("provinceShare").title(year+"年实际划转社保收益").build())
//                .addHeader(HeaderVO.builder().key("socialSecurityBudget").title(year+"年划转社保收益预算数").build())
//                .addHeader(HeaderVO.builder().key("thisBudget").title(year+"年收益执行数").build())
//                .addHeader(HeaderVO.builder().key("thisSecurityExecute").title(year+"年实际划转社保收益").build())
//                .addHeader(HeaderVO.builder().key("remark").title(year+"备注").build())
//        ;
//
//        reportVO.setData(earningsReportVOS);
//        reportReturnVO.setGrids(reportVO);
//        return reportReturnVO;
//    }
//
//    /**
//     * @Description:  获取预算详情
//     * @Author: Take-off
//     * @Date: 10:02 PM 2023/3/6
//     * @Param: [yearSummary]
//     * @return: java.util.List<com.plian.system.entity.pm.listedcompany.EarningsDetail>
//     **/
//    private List<EarningsDetail> getSummaryDetail(List<BaseEarningsSummary> yearSummary,String orgName){
//        List<EarningsDetail> thisYearSummaryDetails = new ArrayList<>();
//        if (CollectionUtil.isNotEmpty(yearSummary)){
//            List<BaseEarningsSummary> gzwYearSummary = yearSummary.stream().filter(item -> item.getFormType().equals(String.valueOf(FormTypeConstant.QM_EARNING_REPORT_GZW))).collect(Collectors.toList());
//            if (CollectionUtil.isNotEmpty(gzwYearSummary)){
//                thisYearSummaryDetails = earningsDetailService.list(new LambdaQueryWrapper<EarningsDetail>().in(EarningsDetail::getBaseId, gzwYearSummary.stream().map(BaseEarningsSummary::getId).collect(Collectors.toList()))
//                        .like(Optional.ofNullable(orgName).isPresent(),EarningsDetail::getFillingOrgName, orgName));
//            }else {
//                thisYearSummaryDetails = earningsDetailService.list(new LambdaQueryWrapper<EarningsDetail>().in(EarningsDetail::getBaseId, yearSummary.stream().map(BaseEarningsSummary::getId).collect(Collectors.toList()))
//                        .like(Optional.ofNullable(orgName).isPresent(),EarningsDetail::getFillingOrgName, orgName));
//            }
//        }
//        return thisYearSummaryDetails;
//    }
//
//    /**
//     * @Description:  获取执行详情
//     * @Author: Take-off
//     * @Date: 10:05 PM 2023/3/6
//     * @Param: [yearExecute]
//     * @return: java.util.List<com.plian.system.entity.pm.listedcompany.EarningsExecuteDetail>
//     **/
//    private List<EarningsExecuteDetail> getExecuteDetail(List<BaseEarningsExecute> yearExecute,String orgName){
//        List<EarningsExecuteDetail> yearExecuteDetails = new ArrayList<>();
//        if (CollectionUtil.isNotEmpty(yearExecute)){
//            List<BaseEarningsExecute> gzwYearSummary = yearExecute.stream().filter(item -> item.getFormType().equals(String.valueOf(FormTypeConstant.QM_EARNING_EXECUTION_REPORT_GZW))).collect(Collectors.toList());
//            if (CollectionUtil.isNotEmpty(gzwYearSummary)){
//                yearExecuteDetails = earningsExecuteDetailService.list(new LambdaQueryWrapper<EarningsExecuteDetail>().in(EarningsExecuteDetail::getBaseId, gzwYearSummary.stream().map(BaseEarningsExecute::getId).collect(Collectors.toList()))
//                        .like(Optional.ofNullable(orgName).isPresent(),EarningsExecuteDetail::getFillingOrgName, orgName));
//            }else {
//                yearExecuteDetails = earningsExecuteDetailService.list(new LambdaQueryWrapper<EarningsExecuteDetail>().in(EarningsExecuteDetail::getBaseId, yearExecute.stream().map(BaseEarningsExecute::getId).collect(Collectors.toList()))
//                        .like(Optional.ofNullable(orgName).isPresent(),EarningsExecuteDetail::getFillingOrgName, orgName));
//            }
//        }
//        return yearExecuteDetails;
//    }
//
//
//    /**
//     * @Description: //TODO 获取其他数据
//     * @Author: Take-off
//     * @Date: 5:12 PM 2023/3/6
//     * @Param: [earningsReportVOS, lastYearExecute, thisYearExecute]
//     * @return: void
//     **/
//    private void getOtherReportVO(List<EarningsReportVO> earningsReportVOS,List<BaseEarningsExecute> lastYearExecute,List<BaseEarningsExecute> thisYearExecute){
//        EarningsReportVO publicFinance = new EarningsReportVO();
//        publicFinance.setFillingOrgName("划转公共财政");
//
//        EarningsReportVO yearCarryOver = new EarningsReportVO();
//        yearCarryOver.setFillingOrgName("上年结转");
//
//        EarningsReportVO availableFunds = new EarningsReportVO();
//        availableFunds.setFillingOrgName("实际可用资金");
//
//        EarningsReportVO expenditure = new EarningsReportVO();
//        expenditure.setFillingOrgName("实际安排支出");
//
//        EarningsReportVO balance = new EarningsReportVO();
//        balance.setFillingOrgName("本年结余");
//
//        if (CollectionUtil.isNotEmpty(lastYearExecute)){
//            BaseEarningsExecute baseEarningsExecute = lastYearExecute.get(0);
//            publicFinance.setLastExecute(baseEarningsExecute.getTransferPublicFinance());
//            yearCarryOver.setLastExecute(baseEarningsExecute.getLastYearCarryOver());
//            availableFunds.setLastExecute(baseEarningsExecute.getActualAvailableFunds());
//            expenditure.setLastExecute(baseEarningsExecute.getActualExpenditure());
//            balance.setLastExecute(baseEarningsExecute.getThisYearBalance());
//        }
//
//        if (CollectionUtil.isNotEmpty(thisYearExecute)){
//            BaseEarningsExecute baseEarningsExecute = thisYearExecute.get(0);
//            publicFinance.setThisBudget(baseEarningsExecute.getTransferPublicFinance());
//            yearCarryOver.setThisBudget(baseEarningsExecute.getLastYearCarryOver());
//            availableFunds.setThisBudget(baseEarningsExecute.getActualAvailableFunds());
//            expenditure.setThisBudget(baseEarningsExecute.getActualExpenditure());
//            balance.setThisBudget(baseEarningsExecute.getThisYearBalance());
//        }
//
//        earningsReportVOS.add(publicFinance);
//        earningsReportVOS.add(yearCarryOver);
//        earningsReportVOS.add(availableFunds);
//        earningsReportVOS.add(expenditure);
//        earningsReportVOS.add(balance);
//    }
//
//    /**
//     * @Description: //TODO 构成合计
//     * @Author: Take-off
//     * @Date: 4:05 PM 2023/3/6
//     * @Param: [earningsReportVOS, index]
//     * @return: void
//     **/
//    private void getTotalReportVO(List<EarningsReportVO> earningsReportVOS){
//        //合计
//        EarningsReportVO total = new EarningsReportVO();
//        total.setFillingOrgName("合计");
//        total.setLastExecute(BigDecimalUtil.addBigDecimals(
//                earningsReportVOS.stream().map(EarningsReportVO::getLastExecute).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList())
//        ));
//        total.setLastSecurityBudget(BigDecimalUtil.addBigDecimals(
//                earningsReportVOS.stream().map(EarningsReportVO::getLastSecurityBudget).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList())
//        ));
//        total.setSocialSecurityBudget(BigDecimalUtil.addBigDecimals(
//                earningsReportVOS.stream().map(EarningsReportVO::getSocialSecurityBudget).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList())
//        ));
//        total.setThisExecute(BigDecimalUtil.addBigDecimals(
//                earningsReportVOS.stream().map(EarningsReportVO::getThisExecute).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList())
//        ));
//        total.setThisSecurityExecute(BigDecimalUtil.addBigDecimals(
//                earningsReportVOS.stream().map(EarningsReportVO::getThisSecurityExecute).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList())
//        ));
//        earningsReportVOS.add(total);
//    }
//
//    /**
//     * @Description:  构成报表类，set今年预算相关字段
//     * @Author: Take-off
//     * @Date: 4:05 PM 2023/3/6
//     * @Param: [executeDetail, earningsReportVO]
//     * @return: void
//     **/
//    private void setReportVO(EarningsDetail earningsDetail,EarningsReportVO earningsReportVO){
//        if (Optional.ofNullable(earningsDetail.getEnterpriseType()).isPresent()){
//            switch (earningsDetail.getEnterpriseType()){
//                case "1":
//                    earningsReportVO.setEnterpriseType("投资服务企业");
//                    break;
//                case "2":
//                    earningsReportVO.setEnterpriseType("运输企业");
//                    break;
//                case "3":
//                    earningsReportVO.setEnterpriseType("教育文化广播");
//                    break;
//                case "4":
//                    earningsReportVO.setEnterpriseType("其他企业");
//                    break;
//                default:
//                    break;
//            }
//        }
//    }
//
//    /**
//     * 统一处理状态机事件方法
//     *
//     * @param id          主键
//     * @param updateStatus  更新状态
//     * @return boolean
//     */
//    private Boolean handleStatus(Long id, int updateStatus,String comment) {
//        try {
//            BaseEarningsExecute baseEarningsExecute = getById(id);
//            /**
//             * 设置审批人和审批时间
//             */
//            if (updateStatus == FormStatusConstant.FINISH){
//                baseEarningsExecute.setApprovedUser(TokenUtil.getTokenUserId());
//                Date now = DateUtil.now();
//                baseEarningsExecute.setApprovedTime(now);
//            }
//
//            if (StringUtil.isNotBlank(baseEarningsExecute.getDataSource()) &&StringUtil.isNotBlank(baseEarningsExecute.getDataSourceId())){
//                if (updateStatus == FormStatusConstant.FINISH || updateStatus == FormStatusConstant.REJECT){
//                    ApprovalMessage approvalMessage = new ApprovalMessage();
//                    approvalMessage.setDataSourceId(baseEarningsExecute.getDataSourceId());
//                    approvalMessage.setType(INVESTMENT_EXECUTION);
//                    approvalMessage.setOpinion(comment);
//                    approvalMessage.setIsApprove(updateStatus == FormStatusConstant.FINISH ? 2 : 1);
//                    approvalMessage.setIsSend(1);
//                    approvalMessage.setDataSourceType(KT_TYPE);
//                    if (baseEarningsExecute.getDataSource().equals(YthConstant.DATA_NINGBO)) {
//                        approvalMessage.setDataSourceType(YthConstant.DATA_NINGBO);
//                        approvalMessage.setFilingUserName(UserCache.userIdToName(TokenUtil.getTokenUserId()));
//                        approvalMessage.setFormType(Integer.parseInt(baseEarningsExecute.getFormType()));
//                        approvalMessage.setFilingCode(baseEarningsExecute.getCode());
//                    }
//                    approvalMessageService.save(approvalMessage);
//                }
//            }
//            baseEarningsExecute.setStatus(updateStatus);
//            updateById(baseEarningsExecute);
//            return true;
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            return false;
//        }
//    }
//
//    @Override
//    @Transactional(rollbackFor = RuntimeException.class)
//    public String saveBaseEarningsExecute(String data){
//        YthResult ythResult = new YthResult();
//        //成功的id集合
//        List<String> successIds = new ArrayList<>();
//        //失败的id集合
//        List<String> failIds = new ArrayList<>();
//        //失败的原因
//        List<String> failReasons = new ArrayList<>();
//        //将json字符串转换成list
//        List<BaseEarningsExecute> dataList = JSON.parseArray(data, BaseEarningsExecute.class);
//        if (CollectionUtil.isNotEmpty(dataList)){
//            Map<String, String> orgSourceMap = orgService.getSourceId();
//            Map<String, String> userSourceMap = userService.getSourceId();
//            //根据datasourceIds 查询出所有的数据
//            List<BaseEarningsExecute> list = list(new LambdaQueryWrapper<BaseEarningsExecute>().in(BaseEarningsExecute::getDataSourceId, dataList.stream().map(BaseEarningsExecute::getDataSourceId).toArray()));
//            //如果数据库中有数据，就更新，没有就新增
//            for (BaseEarningsExecute entity:dataList){
//                transfer(entity,orgSourceMap,userSourceMap);
//                //id重复略过
//                if (CollectionUtil.isNotEmpty(list)){
//                    List<String> olIds = list.stream().map(BaseEarningsExecute::getDataSourceId).collect(Collectors.toList());
//                    String dataSourceId = entity.getDataSourceId();
//                    //判断数据库中是否有数据
//                    if (olIds.contains(dataSourceId)){
//                        for (BaseEarningsExecute oldEntity:list){
//                            if (dataSourceId.equals(oldEntity.getDataSourceId())){
//                                //判断status是否为0，如果是0，就更新，不是0，就不更新
//                                if (CheckStatus.checkCode(oldEntity.getStatus())){
//                                    successIds.add(dataSourceId);
//                                    entity.setId(oldEntity.getId());
//                                    entity.setDataSource(YthConstant.DATA_NINGBO);
//                                    entity.setFormType(String.valueOf(FormTypeConstant.QM_EARNING_EXECUTION_REPORT));
//                                    submit(entity);
//                                    list.remove(oldEntity);
//                                    break;
//                                }else {
//                                    failIds.add(dataSourceId);
//                                    failReasons.add("dataSourceId:"+dataSourceId+"数据已提交且已经在流程中，无法更新");
//                                    break;
//                                }
//                            }
//                        }
//                    }else {
//                        //如果数据库中没有数据，就新增
//                        entity.setDataSource(YthConstant.DATA_NINGBO);
//                        submit(entity);
//                        successIds.add(entity.getDataSourceId());
//                    }
//                }else {
//                    //如果数据库中没有数据，就新增
//                    entity.setDataSource(YthConstant.DATA_NINGBO);
//                    submit(entity);
//                    successIds.add(entity.getDataSourceId());
//                }
//            }
//        } else {
//            failReasons.add("数据为空");
//        }
//        ythResult.setSuccessIds(successIds);
//        ythResult.setFailIds(failIds);
//        ythResult.setFailReason(StringUtils.join(failReasons, ";"));
//        //ythResult转换成json字符串
//        return JSON.toJSONString(ythResult);
//    }
//
//    private void transfer(BaseEarningsExecute entity, Map<String, String> orgSourceMap, Map<String, String> userSourceMap){
//        Optional.ofNullable(entity.getFillingOrgId()).ifPresent(m ->
//                {
//                    String orgId = orgSourceMap.get(m);
//                    if (StringUtil.isNotBlank(orgId)){
//                        entity.setCreateCompanyId(orgId);
//                        entity.setFillingOrgId(orgId);
//                    }
//                }
//        );
//        Optional.ofNullable(entity.getCreateUser()).ifPresent(m ->
//                {
//                    String userId = userSourceMap.get(m);
//                    if (StringUtil.isNotBlank(userId)){
//                        entity.setCreateUser(userId);
//                    }
//                }
//        );
//    }
//}
